package com.genericdevice.platform.core.logging;

/**
 * Created by Xilent on 17.05.2014.
 */
public class LoggerHelper {

    private static LoggerHelper INSTANCE = new LoggerHelper();

    public static LoggerHelper getInstance() {
        return INSTANCE;
    }

    public void error(String message, Throwable reason) {
        log(LogLevel.ERROR, message, reason);
    }

    public void warn(String message) {
        log(LogLevel.WARN, message);
    }

    public void log(String message) {
        log(LogLevel.LOG, message);
    }

    public void log(LogLevel level, String message) {
        log(level, message, null);
    }

    public void log(LogLevel level, String message, Throwable reason) {
        message = getLogLevelMessage(level, message);
        System.out.println(message);
        if (reason == null)
            return;
        reason.printStackTrace();
    }

    private String getLogLevelMessage(LogLevel level, String message) {
        String messagePrefix;

        switch (level) {
            case ERROR :
                messagePrefix = "[ERROR] ";
                break;
            case WARN :
                messagePrefix = "[WARNING] ";
                break;
            case LOG :
                messagePrefix = "[LOG] ";
                break;
            default :
                messagePrefix = "[LOG] ";
        }

        return messagePrefix + message;
    }
}
